package com.bsj.travel.system.controller;

import com.bsj.travel.def.annotation.AdminControl;
import com.bsj.travel.def.common.VO.RoleVO;
import com.bsj.travel.def.common.DTO.web.role.RoleDTO;
import com.bsj.travel.def.common.DTO.web.role.RoleSearchDTO;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.security.annotation.RequiresPermissions;
import com.bsj.travel.system.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @description SysRoleController
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/1/11 16:38
 **/
//@AdminControl
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 添加角色
     *
     * @param roleDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/11 16:46
     */
    @PostMapping("/add")
    @RequiresPermissions(value = "role:operation:add")
    public JsonResult add(@Validated RoleDTO roleDTO) {
        return sysRoleService.addRole(roleDTO);
    }

    /**
     * 删除角色
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/11 16:58
     */
    @PostMapping("/delete/{id}")
    @RequiresPermissions(value = "role:operation:delete")
    public JsonResult delete(@PathVariable("id") Integer id) {
        return sysRoleService.deleteRole(id);
    }

    /**
     * 修改角色
     *
     * @param roleDTO
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/1/11 17:00
     */
    @PostMapping("/update")
    @RequiresPermissions(value = "role:operation:update")
    public JsonResult update(@Validated RoleDTO roleDTO) {
        return sysRoleService.updateRole(roleDTO);
    }

    /**
     * 根绝角色id获取角色信息
     *
     * @param id
     * @return com.bsj.travel.def.global.JsonResult<com.bsj.travel.def.common.VO.RoleVO>
     * @author ljx
     * @time 2024/1/11 17:10
     */
    @GetMapping("/getById/{id}")
    @RequiresPermissions(value = "role:info:getById")
    public JsonResult<RoleVO> getById(@PathVariable("id") Integer id) {
        return JsonResult.success(sysRoleService.getRoleInfoById(id));
    }

    /**
     * 角色分页
     *
     * @param roleSearchDTO
     * @return com.bsj.travel.def.global.JsonResult<java.util.List < com.bsj.travel.def.common.VO.RoleVO>>
     * @author ljx
     * @time 2024/1/11 17:15
     */
    @GetMapping("/page")
    @RequiresPermissions(value = "role:info:page")
    public JsonResult<List<RoleVO>> page(@Validated RoleSearchDTO roleSearchDTO) {
        return sysRoleService.pageRole(roleSearchDTO);
    }

}
